package problema;

import ga.base.Individuo;

public abstract class Solucao implements Comparable<Solucao> {
	protected double[] variaveis;
	protected double fitness;
	/**
	 * @return the variaveis
	 */
	public double[] getVariaveis() {
		return variaveis;
	}
	/**
	 * @param variaveis the variaveis to set
	 */
	public void setVariaveis(double[] variaveis) {
		this.variaveis = variaveis;
	}
	/**
	 * @return the fitness
	 */
	public double getFitness() {
		return fitness;
	}
	/**
	 * @param fitness the fitness to set
	 */
	public void setFitness(double fitness) {
		this.fitness = fitness;
	}

	@Override
	public int compareTo(Solucao solucao) {
		if(fitness < solucao.getFitness()){
			return -1;
		}
		else if(fitness > solucao.getFitness()){
			return 1;
		}
		return 0;
	}

	@Override
	public boolean equals(Object obj) {

		if(!(obj instanceof Individuo)){
			return false;
		}

		Solucao referencia = (Solucao)obj;
		for (int i = 0; i < variaveis.length; i++) {
			if(variaveis[i] != referencia.getVariaveis()[i])
				return false;
		}

		return true;
	}

	@Override
	public String toString() {
		return fitness + "";
	}

}
